package main

import (
	"common/log"
	"common/process"
	"errors"
	"euplink"
	"fmt"
	"github.com/spf13/cobra"
)

var deleteObjectCmd = &cobra.Command{
	Use:   "deleteObject",
	Short: "删除",
	Long:  "euplink deleteObject (local_src)",
	RunE:  cmdDeleteObject,
}

func cmdDeleteObject(cmd *cobra.Command, args []string) error {
	ctx, _ := process.Ctx(cmd)
	if len(args) != 1 {
		return errors.New("参数错误")
	}
	zapLog := log.NewZapLog(&runConfig.Log)
	//runConfig.Project.LocalDeviceId = runConfig.LocalDeviceId
	//runConfig.Project.RootKey = rootKeyToMd5(runConfig.RootKey)
	//runConfig.Project.ApiKey = runConfig.ApiKey
	prj, err := euplink.NewProject(ctx, runConfig.Project, zapLog)
	if err != nil {
		return fmt.Errorf("project init err: %s", err)
	}
	return prj.DeleteObject(ctx, runConfig.Project.DefaultBucket, args[0])
}
